package com.zzchangfu;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.mcp.spring.McpFunctionCallback;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.List;

/**
 * @program: spring-ai
 * @description:
 * @author: liuChangFu
 * @data: 2025-05-12 14:46
 **/
@SpringBootApplication
public class SpringMcpRedisApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringMcpRedisApplication.class, args);
    }

//    @Bean
//    public CommandLineRunner chatWithDatabase(ChatClient.Builder chatClientBuilder, List<McpFunctionCallback> tools) {
//        return args -> {
//            var chatClient = chatClientBuilder
//                    .defaultTools(tools)
//                    .build();
//
//            // 输出可用工具
//            System.out.println("可用的 Tools:");
//            for (McpFunctionCallback tool : tools) {
//                System.out.println(" - " + tool.getToolName() + ": " + tool.getDescription());
//            }
//
//            // 发送问题给 LLM
//            String question = "Redis 中 key 为 'name' 的值是多少？";
//            System.out.println("\n问题: " + question);
//            String response = chatClient.prompt(question).call().content();
//            System.out.println("回答: " + response);
//        };
//    }

    public CommandLineRunner chatWithDatabase(ChatClient.Builder chatClientBuilder, FunctionCallback[] tools) {
        return args -> {
            var chatClient = chatClientBuilder
                    .defaultFunctions(tools)
                    .build();

            // 输出当前可用的工具列表
            System.out.println("可用的 Tools:");
            for (FunctionCallback tool : tools) {
                System.out.println(" - " + tool.getName() + ": " + tool.getDescription());
            }

            String question = "Redis 中 key 为 'name' 的值是多少？";
            System.out.println("问题: " + question);
            String response = chatClient.prompt(question).call().content();
            System.out.println("回答: " + response);
        };
    }
}
